package com.huike.business.service.impl;

import com.huike.business.domain.TbBusiness;
import com.huike.business.domain.TbBusinessTrackRecord;
import com.huike.business.domain.vo.BusinessTrackVo;
import com.huike.business.mapper.TbBusinessMapper;
import com.huike.business.mapper.TbBusinessTrackRecordMapper;
import com.huike.business.service.TbBusinessTrackRecordService;
import com.huike.common.core.controller.BaseController;
import com.huike.common.utils.SecurityUtils;
import com.huike.common.utils.bean.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: fwh
 * @Date: 2023/07/12/22:07
 * @Description:
 */
@Service
public class TbBusinessTrackRecordServiceImpl implements TbBusinessTrackRecordService {
    @Resource
    private TbBusinessTrackRecordMapper tbBusinessTrackRecordMapper;
    @Resource
    private TbBusinessMapper tbBusinessMapper;


     /**
     * 新增商品跟进记录
     *
     * @param businessTrackVo
     */
    @Override
    public int add(BusinessTrackVo businessTrackVo) {
        //封装跟进信息
        TbBusinessTrackRecord record = new TbBusinessTrackRecord();
        record.setCreateBy(SecurityUtils.getUsername());
        BeanUtils.copyProperties(businessTrackVo,record);
        TbBusiness tbBusiness = new TbBusiness();
        BeanUtils.copyProperties(businessTrackVo,tbBusiness);
        //更新商机表数据
        //设置状态
        tbBusiness.setId(businessTrackVo.getBusinessId());
        tbBusiness.setStatus("2");
        tbBusinessMapper.update(tbBusiness);

        return tbBusinessTrackRecordMapper.add(record);
    }

    /**
     * 查询商机跟进记录
     *
     * @param id
     * @return
     */
    @Override
    public List<TbBusinessTrackRecord> getBusinessTrackRecord(Long id) {
        return tbBusinessTrackRecordMapper.getBusinessTrackRecord(id);
    }

    /**
     * 获取商机跟进记录详细信息
     *
     * @param id
     * @return
     */
    @Override
    public TbBusinessTrackRecord getById(Long id) {
        TbBusinessTrackRecord tbBusinessTrackRecord=tbBusinessTrackRecordMapper.getById(id);
        return tbBusinessTrackRecord;
    }
}
